#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2025/1/27 21:53
# @Author  : Ramsey
# @Site    : zh
# @File    : transform.py
# @Software: PyCharm
from typing import Callable
from inspect import iscoroutine, isgenerator, isasyncgen, iscoroutinefunction
from spider_framework.utils.error import TransFormError


async def transform_outputs(outputs):
    """
    将outputs转换为request
    :param outputs:
    :return:
    """
    if isgenerator(outputs):
        for _ in outputs:
            yield _
    elif isasyncgen(outputs):
        async for _ in outputs:
            yield _
    else:
        raise TransFormError("不存在该类型")


async def common_call(func: Callable, *args, **kwargs):
    if iscoroutinefunction(func):
        return await func(*args, **kwargs)
    else:
        return func(*args, **kwargs)


if __name__ == "__main__":
    pass
